package com.dwb.controller;

import com.dwb.entity.SSlide;
import com.dwb.result.Result;
import com.dwb.service.SSlideService;
import com.dwb.utils.Empty;
import com.github.pagehelper.PageInfo;
import com.sun.org.apache.xerces.internal.impl.xpath.XPath;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @Author manke
 * @Date 2020/6/27 17:38
 * @Version 0.0.1
 */
@Api(value = "SSlide",description = "轮播图控制器")
@RestController
@RequestMapping("SSlide")
public class SSlideController {
    @Autowired
    private SSlideService sSlideService;

    /**
     * 获取轮播图详情信息
     * @param parameters 传入主键id
     * @return
     */
    @ApiOperation(value = "getInfo",notes = "获取轮播图详情信息")
    @PostMapping("/getInfo")
    public Result<SSlide> getInfo(@RequestBody Map<String ,String> parameters){
        Result<SSlide> result = Result.newSuccess();
        SSlide sSlide = sSlideService.getInfo(parameters);
        result.setDataMap(sSlide);
        return result;

    }

    /**
     * 轮播图删除
     * @param parameters
     * @return
     */
    @PostMapping("/delete")
    @ApiOperation(value = "delete",notes = "轮播图删除")
    public Result<String> delete(@RequestBody Map<String ,String> parameters){
        sSlideService.delete(parameters);
        return Result.newSuccess();


    }

    /**
     * 轮播图添加或者修改
     * @param sSlide
     * @return
     */
    @PostMapping("/addOrUpdate")
    @ApiOperation(value = "addOrUpdate",notes = "轮播图添加或者修改")
    public Result<String> addOrUpdate(@RequestBody SSlide sSlide){
        if (Empty.INT_EMPTY(sSlide.getId())){
            //添加
            sSlideService.add(sSlide);
        }else {
            //修改
            sSlideService.update(sSlide);
        }


        return Result.newSuccess();
    }

    @PostMapping("/getList")
    @ApiOperation(value = "getList",notes = "获取轮播图列表")
    public Result<PageInfo<SSlide>> getList(@RequestBody Map<String ,String> parameters){
        Result<PageInfo<SSlide>> result = Result.newSuccess();
        PageInfo<SSlide> list = sSlideService.getList(parameters);

        result.setDataMap(list);
        return result;

    }

}
